﻿using Enyim.Caching.Memcached;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GuoZhiQi.MiddleCache
{
    /// <summary>
    /// 用来处理由CouchBase引发的异常信息处理
    /// </summary>
    public class CouchBaseException : Exception
    {
        /// <summary>
        /// CouchBase 异常信息捕获
        /// </summary>
        /// <param name="key"></param>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        public CouchBaseException(string key,string message,Exception innerException)
            :base(message,innerException)
        {
            this.ItemKey = key;
            this.StoreMode = null;
        }

        public CouchBaseException(string key,StoreMode storeMode,string message,Exception innerException)
            :base(message,innerException)
        {
            this.ItemKey = key;
            this.StoreMode = storeMode;
        }

        /// <summary>
        /// 获取引发异常信息的key
        /// </summary>
        public string ItemKey { get; private set; }
        /// <summary>
        /// 获取引发异常信息的StoreMode
        /// </summary>
        public StoreMode? StoreMode { get; set; }

        public override string Message
        {
            get
            {
                string fullMessage = base.Message + "/r/n Key affected:" + this.ItemKey + "/r/n StoreMode:";
                if (this.StoreMode.HasValue)
                {
                    fullMessage += this.StoreMode.ToString();
                }
                else
                {
                    fullMessage += "Not_Store";
                }
                return fullMessage;
            }
        }
    }
}
